package com.erp.myAdapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.TextView
import androidx.core.content.ContextCompat
import com.erp.R
import com.erp.bean.ProductionExecuteBean
import com.erp.util.Myutil
import kotlinx.android.synthetic.main.lv_production_execute_item.view.*

class ProductionExecuteAdapter(private val mlist: List<ProductionExecuteBean>, private val mcontext: Context): BaseAdapter() {
    private val minflater: LayoutInflater = LayoutInflater.from(mcontext)
    override fun getCount(): Int {
        return mlist.size
    }

    override fun getItem(i: Int): Any {
        return mlist[i]
    }

    override fun getItemId(i: Int): Long {
        return i.toLong()
    }

    override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
        var v : View
        val h: ViewHolder
        if (convertView == null) {
            v = minflater.inflate(R.layout.lv_production_execute_item, null)
            h = ViewHolder(v)
            v.tag = h
        } else {
            v=convertView
            h = convertView.tag as ViewHolder
        }
        val bean = mlist[position]
        Myutil.settv(bean.count,h.TvCount)
        Myutil.settv(bean.elevator_number,h.TvElevatorNumber)
        Myutil.settv(bean.workshop,h.TvWorkshop)
        Myutil.settv(bean.status_name,h.TvStatusName)
        Myutil.settv(bean.heap_number,h.TvHeapNumber)
        Myutil.settv(Myutil.getdata(bean.productive_time),h.TvProductiveTime)
        Myutil.settv(bean.thickness,h.TvThickness)
        Myutil.settv(bean.stock_name,h.TvStock)
        if(bean.status == "4"){
            h.Llitem.setBackgroundColor(ContextCompat.getColor(mcontext,R.color.palegreen))
//            h.Llitem.setBackgroundColor(Color.parseColor("#98fb98"))
        }else{
            h.Llitem.setBackgroundColor(ContextCompat.getColor(mcontext,R.color.white))
        }
        return  v;
    }

    internal class ViewHolder(v: View) {
        var TvStatusName:TextView = v.TvStatusName
        var TvHeapNumber:TextView = v.TvHeapNumber
        var TvWorkshop:TextView = v.TvWorkshop
        var TvElevatorNumber:TextView = v.TvElevatorNumber
        var TvCount:TextView = v.TvCount
        var TvThickness = v.TvThickness
        var TvProductiveTime = v.TvProductiveTime
        var Llitem = v.Llitem
        var TvStock = v.TvStock

    }

}